/*
 * @Author: gggg 1263457581@qq.com
 * @Date: 2025-06-09 10:42:41
 * @LastEditors: gggg 1263457581@qq.com
 * @LastEditTime: 2025-06-09 11:07:11
 * @FilePath: /algorithm-and-data-struct/datastruct/MyPriorityQueue.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/***
最小堆
std::priority_queue<int, std::vector<int>, std::less<int>> minHeap;

最大堆
std::priority_queue<int, std::vector<int>, std::greater<int>> minHeap;
 

struct MyCompare {
    bool operator()(const int& a, const int& b) {
        return a > b; // 使得最大元素在顶部，类似于 std::less 的效果，但可以修改为任何逻辑
    }
};
std::priority_queue<int, std::vector<int>, MyCompare> customHeap;
    

auto lambdaComp = [](const int& a, const int& b) { return a > b; }; // 最大元素在顶部
std::priority_queue<int, std::vector<int>, decltype(lambdaComp)> customHeap(lambdaComp);
    


*/
#include <functional>
#include <queue>
class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 
     * @param input int整型vector 
     * @param k int整型 
     * @return int整型vector
     */
    static bool cmp(const int& a, const int& b)
    {
        return a < b;
    }
    vector<int> GetLeastNumbers_Solution(vector<int>& input, int k) {
        // write code here
        vector<int> res;
        if (k == 0) return res;
        priority_queue<int, vector<int> > pq;
        for(int i = 0; i < k; i++){
            pq.push(input[i]);
        }
        for(int i = k; i < input.size(); i++){
            if (input[i] < pq.top()){
                pq.pop();
                pq.push(input[i]);
            }
        }

        while (!pq.empty()) {
            res.push_back(pq.top());
            pq.pop();
        }
        return res;
    }
};